package GreedyAlgorithmPackage;

import org.junit.jupiter.api.Test;

/**
 * @author Lzm
 * @version 1.0
 */
  /*不看具体跳多少步, 看覆盖范围*/

public class canJump_ {
  @Test
  public void canJumpTest(){
    //int[] nums = new int[]{2,3,1,1,4};
    int[] nums = new int[]{3,2,1,0,4};
    System.out.println(canJump(nums));
  }
  public boolean canJump(int[] nums) {
    if (nums.length == 1){
      return true;
    }
    int result = 0;
    for (int i = 0 ; i <= result ; i ++){
      /*取最大的覆盖范围*/
      result = Math.max(result,i + nums[i]);
      if (result >= nums.length - 1){
        return true;
      }
    }
    return false;
  }
}
